﻿using System;
using DotNetNeural.Perceptron.Initialization;
using DotNetNeural.Utils;

namespace DotNetNeural.Activation
{
    /// <summary>
    /// Implementes default sigmoidal activation function and corresponding weightes initializer
    /// </summary>
    public class DefaultPerceptronSettings : IActivationFunc, IWeightsInitializer
    {
        #region IActivationFunc Members

        public float Min
        {
            get
            {
                return 0;
            }
        }

        public float Max
        {
            get
            {
                return 1;
            }
        }


        public Func<float, float> Activation
        {
            get
            {
                return new Func<float, float>(
                    (x) => (float)(1 / (1 + Math.Exp(-x)))
                );
            }
        }

        public Func<float, float> DerivativeActivation
        {
            get
            {
                return new Func<float, float>(
                      (x) =>
                      {
                          float fx = (float)(1 / (1 + Math.Exp(-x)));
                          return fx * (1 - fx);
                      }
                    );
            }
        }

        #endregion

        #region IWeightsInitializer Members

        public float GenerateValue()
        {
            return (float)rnd.NextDouble(-0.3, 0.3);
        }

        #endregion

        CryptoRandom rnd = new CryptoRandom();
    }
}
